package com.echo.im.platform.controller;


import com.echo.im.common.result.Result;
import com.echo.im.common.vo.GroupMessageVO;
import com.echo.im.domain.group.dto.PullGroupOfflineMessageDTO;
import com.echo.im.domain.message.service.GroupMessageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * @author echo
 * @date 2024-08-18
 */
@Tag(name = "群聊消息")
@RestController
@RequestMapping("/message/group")
@RequiredArgsConstructor
public class GroupMessageController {

    private final GroupMessageService groupMessageService;

//    @PostMapping("/send")
//    @Operation(summary = "发送群聊消息", description = "发送群聊消息")
//    public Result<GroupMessageVO> sendMessage(@Valid @RequestBody GroupMessageDTO vo) {
//        return Result.success(groupMessageService.sendMessage(vo));
//    }
//
//    @DeleteMapping("/recall/{groupId}/{msgId}")
//    @Operation(summary = "撤回消息", description = "撤回群聊消息")
//    public Result<Long> recallMessage(@NotNull(model = "消息id不能为空") @PathVariable Long msgId, @PathVariable Long groupId) {
//        groupMessageService.recallMessage(groupId,msgId);
//        return Result.success();
//    }
//    @PutMapping("/ackMessage")
//    @Operation(summary = "消息已读回执", description = "将群聊中的消息状态置为已读")
//    public Result ackMessage(@RequestBody GroupMessageACKDTO dto) {
//        groupMessageService.ackMessage(dto);
//        return Result.success();
//    }


    @GetMapping("/pullOfflineMessage")
    @Operation(summary = "拉取离线消息", description = "拉取离线消息,消息将通过webscoket异步推送")
    public Result<List<GroupMessageVO>> pullOfflineMessage(@RequestParam PullGroupOfflineMessageDTO dto) {
        List<GroupMessageVO> groupMessageVOList = groupMessageService.pullOfflineMessage(dto);
        return Result.success(groupMessageVOList);
    }


    @GetMapping("/findReadedUsers")
    @Operation(summary = "获取已读用户id", description = "获取消息已读用户列表")
    public Result<List<Long>> findReadedUsers(@RequestParam Long groupId,
                                              @RequestParam Long messageId) {
        return Result.success(groupMessageService.findReadedUsers(groupId, messageId));
    }

    @GetMapping("/history")
    @Operation(summary = "查询聊天记录", description = "查询聊天记录")
    public Result<List<GroupMessageVO>> recallMessage(@NotNull(message = "群聊id不能为空") @RequestParam Long groupId,
        @NotNull(message = "页码不能为空") @RequestParam Long lastMsgId,
        @NotNull(message = "size不能为空") @RequestParam Long size) {
        return Result.success(groupMessageService.findHistoryMessage(groupId, lastMsgId, size));
    }
}

